package com.muyi.biling.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.support.v4.app.Fragment;
import android.widget.Toast;

import com.google.zxing.activity.CaptureActivity;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.parceler.Parcels;

import java.util.ArrayList;

import com.muyi.biling.R;
import com.muyi.biling.bean.CommodityItem;
import com.muyi.biling.ui.OrderEditActivity_;
import com.muyi.biling.ui.OrderReviewActivity;
import com.muyi.biling.ui.OrderReviewActivity_;
import com.muyi.biling.util.Utils;

/**
 * Created by developer on 18-1-24.
 */

@EFragment(R.layout.frag_cart)
public class CartFragment extends Fragment {

    private final int QR_SCAN_CODE = 1;

    @Click(R.id.frag_cart_btn)
    void toOrderReview() {
//        Intent intent = new Intent(getActivity(), OrderEditActivity_.class);
//        ArrayList<CommodityItem> data = new ArrayList<>();
//        for (int i = 0; i < 20; i ++) {
//            data.add(new CommodityItem("巴花实木大板280*190*10", 1, 8000, 8000, ""));
//        }
//
//        intent.putExtra(CommodityItem.CLASS_NAME, Parcels.wrap(data));
//        startActivity(intent);

        Intent intent = new Intent(getActivity(), CaptureActivity.class);
        startActivityForResult(intent, QR_SCAN_CODE);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == QR_SCAN_CODE && resultCode == CaptureActivity.RESULT_CODE_QR_SCAN) {
            Bundle bundle = data.getExtras();
            String scanResult = bundle.getString(CaptureActivity.INTENT_EXTRA_KEY_QR_SCAN);
            Toast.makeText(getActivity(), scanResult, Toast.LENGTH_SHORT).show();
//            Utils.showToastShort(scanResult);
        }
    }
}
